﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BTL_SQL
{
    class AccessData
    {
        public SqlConnection GetConnect() 
        {
            return new SqlConnection("Data Source=trantai-pc;Initial Catalog=QUANLY_TRUONG_THPT;Integrated Security=True");
        }
        public SqlDataReader ExcuteReader(string s)
        {
            SqlConnection con = GetConnect();
            con.Open();
            SqlCommand cmd = new SqlCommand(s, con);
            SqlDataReader reader = cmd.ExecuteReader();
            cmd.Dispose();
            return reader;
        }
        public void ExecuteNonQuery(string s)
        {
            SqlConnection con = GetConnect();
            con.Open();
            SqlCommand cmd = new SqlCommand(s, con);
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            con.Close();
        }
        public string ExecuteScalar(string s)
        {
            SqlConnection con = GetConnect();
            con.Open();
            SqlCommand cmd = new SqlCommand(s, con);
            string ss = cmd.ExecuteScalar().ToString();
            cmd.Dispose();
            con.Close();
            return ss;
        }
        public DataTable GetTable(string s)
        {
            SqlConnection con = GetConnect();
            SqlDataAdapter ad = new SqlDataAdapter(s, con);
            DataTable dt = new DataTable();
            ad.Fill(dt);
            return dt;
        }
    }
}
